import java.util.*;
    public class Muster {
        public Set<Character> unite = new LinkedHashSet<Character>();
        public Set<Character> intersection = new LinkedHashSet<Character>();
        public Set<Character> differenceA2B = new LinkedHashSet<Character>();
        public Set<Character> differenceB2A = new LinkedHashSet<Character>();

        public Muster(String muster1, String muster2) {
            muster1 = muster1.replaceAll("[^a-z]", "");
            muster2 = muster2.replaceAll("[^a-z]", "");
            for (Character temp : muster1.toCharArray()) {
                //添加并集
                unite.add(temp);
                if (muster2.indexOf(temp) >= 0) {
                    intersection.add(temp);
                } else {
                    differenceA2B.add(temp);
                }
            }
            for (Character temp : muster2.toCharArray()) {
                unite.add(temp);
                if (muster1.indexOf(temp) >= 0) {
                    intersection.add(temp);
                } else {
                    differenceB2A.add(temp);
                }
            }
        }
        public static void main(String[] args) {
            char[] str1 = new char[100];
            char[] str2 = new char[100];
            char[] str3 = new char[100];
            char temp;
            String string1, string2, replace = null;
            Scanner scan = new Scanner(System.in);
            System.out.println("请输入第一串字符");
            string1 = scan.nextLine();
            str1 = string1.toCharArray();
            replace = string1;
            for (int i = 0; i < string1.length(); i++) {
                for (int j = string1.length() - 1; j > i; j--) {
                    if (str1[j] <= str1[j - 1]) {
                        temp = str1[j];
                        str1[j] = str1[j - 1];
                        str1[j - 1] = temp;
                    }
                }
            }
            String i = String.valueOf(str1);

            System.out.println("请输入第二串字符");
            string2 = scan.nextLine();
            str2 = string2.toCharArray();
            replace = string2;
            for (int a = 0; a < string2.length(); a++) {
                for (int j = string2.length() - 1; j > a; j--) {
                    if (str2[j] <= str2[j - 1]) {
                        temp = str2[j];
                        str2[j] = str2[j - 1];
                        str2[j - 1] = temp;
                    }
                }
            }
            String j = String.valueOf(str2);//将 char 变量 c 转换成字符串

            Muster muster = new Muster(i, j);
            str3 = muster.getUnite().toCharArray();
            replace = muster.getUnite();
            for (int a = 0; a < muster.getUnite().length(); a++) {
                for (int k = muster.getUnite().length() - 1; k > a; k--) {
                    if (str3[k] <= str3[k - 1]) {
                        temp = str3[k];
                        str3[k] = str3[k - 1];
                        str3[k - 1] = temp;
                    }
                }
            }
            String k = String.valueOf(str3);


            System.out.println("Set1∪Set2=" + k);
            System.out.println("Setl∩Set2=" + muster.getIntersection());
            System.out.println("Set1-Set2=" + muster.getDifferenceA2B());
            System.out.println("Set2-Set1=" + muster.getDifferenceB2A());


        }
        public String getUnite() {
            return getStringBySet(unite);
        }
        public String getIntersection() {
            return getStringBySet(intersection);
        }
        public String getDifferenceA2B() {
            return getStringBySet(differenceA2B);
        }
        public String getDifferenceB2A() {
            return getStringBySet(differenceB2A);
        }
        private String getStringBySet(Set<Character> set) {
            StringBuffer result = new StringBuffer();
            for (Character c : set) {
                result.append(c);
            }
            return result.toString();
        }

    }


